using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Keep.Util;

public class FileUtil
{
    public static bool IsImageFile(FileInfo fileInfo)
    {
        string extension = Path.GetExtension(fileInfo.FullName).ToLowerInvariant();
        if (!String.IsNullOrEmpty(extension))
        {
            if (extension.Equals(".jpg")
            || extension.Equals(".jpeg")
            || extension.Equals(".png")
            || extension.Equals(".gif")
            || extension.Equals(".bmp")
            || extension.Equals(".webp"))
            {
                return true;
            }
        }

        return false;
    }
    //删除目录及子目录所有文件
    public static void DeleteDirectoryRecursively(string directoryPath)
    {
        if (!Directory.Exists(directoryPath))
        {
            return;
        }

        // 首先递归删除所有子目录和文件
        foreach (string dir in Directory.GetDirectories(directoryPath))
        {
            DeleteDirectoryRecursively(dir); // 递归删除子目录
        }

        // 然后删除当前目录下的所有文件
        foreach (string file in Directory.GetFiles(directoryPath))
        {
            File.Delete(file);
        }

        // 最后删除当前空目录
        Directory.Delete(directoryPath);
    }
}
